package com.fiap.controleLancamentos.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.Session;

import com.fiap.controleLancamentos.dao.UsuarioDao;
import com.fiap.controleLancamentos.manager.UsuarioBean;
import com.fiap.controleLancamentos.manager.UsuarioManager;

/**
 * Servlet implementation class ServletLogin
 */
@WebServlet("/logar")
public class ServletLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ServletLogin() {
		super();
		// TODO Auto-generated constructor stub
	}

	protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
	}

	protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		UsuarioManager manager = new UsuarioManager();
		UsuarioBean usu = new UsuarioBean();
		usu.setLogin(request.getParameter("login"));
		usu.setSenha(request.getParameter("senha"));

		try {
			if(manager.validarUsuario(usu)){
				HttpSession session = request.getSession();
				session.setAttribute("UsuarioBean", usu);
			}else{
				System.out.println("acesso invalido");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
